package com.journey.org.ui.video.broadcast

import androidx.databinding.ObservableField
import com.journey.org.entity.DataRecommend
import com.mvvmhabit.org.base.MultiItemViewModel
import com.mvvmhabit.org.binding.command.BindingAction
import com.mvvmhabit.org.binding.command.BindingCommand
import com.mvvmhabit.org.utils.loadTimeByLong

/**
 * @Date: 2020/11/20 15:49
 * @Author:小妖
 * @Description:
 */
class BroadcastBodyItemViewModel(vm: BroadcastViewModel, val entity: DataRecommend) :
    MultiItemViewModel<BroadcastViewModel>(vm) {

    val content = ObservableField<String>()

    val showTime = loadTimeByLong(entity.duration.toLong())

    init {
        content.set("#" + entity.category + " / " + entity.author!!.name)
    }

    val onEnterVideoCommand = BindingCommand<Any>(object : BindingAction {
        override fun call() {
            viewModel.videoTitleField.set(entity.title)
            viewModel.videoDesField.set(entity.description)
            if (entity.author != null) {
                viewModel.videoContentField.set("#" + entity.category + " / " + entity.author.name)
            }
            viewModel.loadVideoHeaderData()
            viewModel.videoUrlField.call(entity.playUrl)
            viewModel.loadVideoBodyData(entity.id.toString())
        }
    })
}